package order

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"shop/formdata"
	"shop/internal/controller/base"
	order2 "shop/internal/server/order"
)

// 订单创建
func OrderCreation(c *gin.Context) {
	order := new(order2.CreateOrderReq)
	if err := c.ShouldBindJSON(&order); err != nil {
		base.RespData(c, nil, err)
		return
	}
	userID := c.GetUint("user_id")
	create, err := order2.CreateOrder(userID, order)
	if err != nil {
		return
	}
	base.RespData(c, create, nil)
}

// 更新支付的状态
func UpdateByState(c *gin.Context) {
	var order formdata.Order
	if err := c.ShouldBindJSON(&order); err != nil {
		base.RespData(c, nil, err)
		return
	}
	if order.OrderID < 0 {
		base.RespData(c, nil, fmt.Errorf("orderID不能小于等于0"))
		return
	}
	status, err := order2.UpdateStatus(order.OrderID)
	if err != nil {
		return
	}
	base.RespData(c, status, nil)
}

/*// 删除订单
func OrderByOrderIdDel(c *gin.Context) {
	userID := c.GetUint("user_id")

}

// 取消订单
func OrderByOrderIdCancel(c *gin.Context) {
	userID := c.GetUint("user_id")

}

// 查询订单及其商品
func GetOrderProductInfoByOrderId(c *gin.Context) {
	userID := c.GetUint("user_id")

}

// 订单号查询订单
func GetOrderByNo(c *gin.Context) {
	userID := c.GetUint("user_id")

}

// 查询用户的订单详情
func GetUserListById(c *gin.Context) {
	userID := c.GetUint("user_id")

}

// 处理订单支付状态
func OrderPay(c *gin.Context) {
	userID := c.GetUint("user_id")

}*/
